-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(config): write temporary vite config to node_modules #18509
Conversation
This PR does not work with escaped dynamic imports which is one of the reasons we reverted #13269. For example if you prepend the following content in the const dynImport = (id) => {
return import(id)
}
globalThis.__STRINGIFIED_OBJ__ = 'foo'
const result = await dynImport('./commonjs-dep/index.js')
console.log('result', result) |
To fix this, we need to replace dynamic imports with something else and resolve it on our side like #17894 did. I wonder if we can avoid the global function by exposing an internal function from |
We currently already not have good support for escaped dynamic imports. We bundle all code from different files to a single file, so that means the source files that're within the same directory as Usually it's also more common for escaped dynamic imports on dependencies rather than paths, and it'll still work in this PR. Checking the repro in #13730 which caused the revert, it seems to still work well with this PR. |
Ah, that's true. Sounds good to me to try it out. |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress |
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Christoph tested the PR with Athena Crisis too, and everything looks green. Let's try this out.
this doesn't really help in cases where node_modules are not writable |
I am using NIX to manage NodeJS packages, which results in Upgrading to Vite v6+ results in Vite no longer being able to start because of that. See also: #18839 |
Readonly node_modules will cause issues with not just vite. Many tools write temp files to I just wish that vite would also use |
Upgrading to 6.0.3 broke my build today as I also use a readonly |
Update from the future: #18637 introduces a new option to run Vite without writing a bundled config file |
Description
Closes #13267
Closes #9470
After reviewing #17894, I was figuring if there's another way to fix this. Many folks in the linked issues about suggested writing the temporary file to
node_modules/.vite
, which is what this PR eventually does.At the time, this solution wasn't feasible because it breaks relative references, node_module resolution, and references between workspace packages. Over time we kinda indirectly addressed them by bundling all relative imports and workspace packages, rewrite all external imports to node_modules, and shim
import.meta.*
. So in most cases everything is self-contained, except for the rare case ofeval()
but that's not as common.So it seems like we can actually put the temporary file in
node_modules
now, specifically likenode_modules/.vite/configs/vite.config.mjs-timestamp-*-*.mjs
. I couldn't think of a case where this would break, but I haven't really tested this more robustly either yet.FWIW I listed some other alternatives and I did make a branch to support solution 2, but this PR may be the better ootb solution if it works.